import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/utils/interface.dart';
import 'package:safetymonitor/app/core/utils/user_manager.dart';
import 'package:safetymonitor/router/app_pages.dart';

class UserControl extends GetxController {

  /// 点击版本信息
  void onTapVersion() {
    Get.toNamed(Routes.personalVersionInfo);
  }

  /// 点击帮助
  void onTapHelp() {
    Get.toNamed(Routes.personalHelp);
  }

  /// 点击设置
  void onTapSetting() {
    // Get.to(TestPage.new);
    Get.toNamed(Routes.personalSetting);
  }

  /// 获取头像路径
  String getAvatarPath() {
    final avatar = UserManager.getUser()?.avatar ?? '';
    if (avatar == '') {
      return '';
    } else {
      return avatar.contains('http') ? avatar : Interface.fileUrl + avatar;
    }
  }

  /// 获取岗位显示
  String getPosts() {
    return (UserManager.getUser()?.posts ?? []).map((e) => e.name).join(',');
  }

  /// 获取角色
  String getRoles() {
    return (UserManager.getUser()?.roles ?? []).map((e) => e.name).join(',');
  }
}
